﻿
using System.Collections.Generic;
using System.Web.Script.Serialization;

namespace MNH.WebApps.Common.Helpers.JqGrid
{
  public static class ObjectExtensions
  {
    public static string ToJSON(this object obj)
    {
      JavaScriptSerializer scriptSerializer = new JavaScriptSerializer();
      scriptSerializer.RegisterConverters((IEnumerable<JavaScriptConverter>) new JavaScriptConverter[1]
      {
        (JavaScriptConverter) new NullPropertiesConverter()
      });
      return scriptSerializer.Serialize(obj);
    }

    public static string ToJSON(this object obj, int recursionDepth)
    {
      JavaScriptSerializer scriptSerializer = new JavaScriptSerializer();
      scriptSerializer.RegisterConverters((IEnumerable<JavaScriptConverter>) new JavaScriptConverter[1]
      {
        (JavaScriptConverter) new NullPropertiesConverter()
      });
      scriptSerializer.RecursionLimit = recursionDepth;
      return scriptSerializer.Serialize(obj);
    }
  }
}
